<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>非父子组件间传值问题（Bus/总线/发布订阅模式/观察者模式）</title>
</head>
<body>
    <div id="root">
        <counter :count="0" @inc="handleIncrease"></counter>
        <counter :count="0" @inc="handleIncrease"></counter>
        <div>{{total}}</div>
    </div>
    <p>解决非父组件之间传值的问题有两种方式：</p>
    <p>1.开发订阅模式</p>
    <p>2.vuex</p>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        var counter={
            props:['count'],
            data:function(){
                return {
                    number:this.count
                }
            },
            template:"<div @click='handleClick'>{{number}}</div>",
            methods:{
                handleClick:function(){
                    this.number++;
                    this.$emit('inc',1);
                }
            }
        }
        var app=new Vue({
            el:"#root",
            components:{
                counter:counter
            },
            data:{
                total:0
            },
            methods:{
                handleIncrease:function(num){
                    this.total+=num;
                }
            }
        })
    </script>
</body>
</html>